rm -rf output
mkdir output

cho "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "[INFO]开始更新代码......远端代码将会完全覆盖本地代码"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"

git reset --hard
git pull

echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "[INFO]开始Maven打包......"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
mvn clean package -Dmaven.test.skip=true


if [ $? -ne 0 ]; then
    echo ""
    echo "***********************************************************"
    echo "[INFO]Maven打包失败"
    echo "***********************************************************"
    exit 1
fi
cp Dockerfile output/Dockerfile
cp target/urp-core-1.0-SNAPSHOT.jar output/urp-core.jar


docker stop urp-core
docker rm urp-core
docker rmi urp-core:0.0.1

echo '>>> old container removed'

echo '================开始构建镜像================'
cd output
docker build -t urp-core:0.0.1 .
echo '================结束构建镜像================'


echo '================开始运行新容器================'
docker run -itd -p 8001:8001 --restart always --name=urp-core --privileged=true urp-core:0.0.1
echo '================运行新容器完毕================'


echo '================结束远程启动================'